import requests
import json
from AppModel.models import *

class zySDK:
    def post_to_zy(ob,fg_type,logger):
        url = 'http://111.30.78.81:8018/third/sysService.jsp?method=bbxxsj&body=['
        params_json = json.loads(json.dumps(ob))
        items = params_json.items()
        for key, value in items:
            if str(key) == 'user_name':
                url =url+'{"name":"姓名","value":"'+str(value)+'"},'
            if str(key) == 'phone_number':
                url =url+'{"name":"主手机号","value":"'+str(value)+'"},'
            if str(key) == 'covid_test_report_img':
                url =url+'{"name":"核算报告","value":"https://brilliantlife.com.cn:8020/'+str(value)+'"},'
            if str(key) == 'user_type':
                v = "-1011829781299903333"
                if str(value) == "1":
                    v = "-2697056394220843866"
                if str(value) == "2":
                    v = "-6628758109765353450"
                if str(value) == "3":
                    v = "-6848205106814367273"
                if str(value) == "4":
                    v = "8589023072944867380"
                url =url+'{"name":"人员类型","value": "'+v+'"},'
            if str(key) == 'credential_type':
                v1 = "-2163949937512004517"
                if str(value) == "1":
                    v1 = "-120587067059975033"
                url =url+'{"name":"证件类型","value": '+v1+' },'
            if str(key) == 'id_card_num':
                url =url+'{"name":"证件号","value":"'+str(value)+'"},'
            if str(key) == 'company_name':
                url =url+'{"name":"单位名称","value":"'+str(value)+'"},'
            if str(key) == 'work_area':
                url =url+'{"name":"工作区域或者岗位","value":"'+str(value)+'"},'
            if str(key) == 'habitation_area':
                v6 = "6249666976084412847"
                if str(value) == "0":
                    v6 = "6249666976084412847"
                if str(value) == "1":
                    v6 = "7577884879151841687"
                if str(value) == "2":
                    v6 = "-1841404495153902540"
                if str(value) == "3":
                    v6 = "-7836971642085881951"
                if str(value) == "4":
                    v6 = "-7022987771455910953"
                if str(value) == "5":
                    v6 = "-7436135588797857361"
                if str(value) == "6":
                    v6 = "3562988799050337284"
                if str(value) == "7":
                    v6 = "-559088388398299686"
                if str(value) == "8":
                    v6 = "6112140215708893861"
                if str(value) == "9":
                    v6 = "-6528412264235514711"
                if str(value) == "10":
                    v6 = "8632096367376154741"
                if str(value) == "11":
                    v6 = "1067848193873626121"
                if str(value) == "12":
                    v6 = "-7403414504862822800"
                if str(value) == "13":
                    v6 = "1353876058778518827"
                if str(value) == "14":
                    v6 = "1601061402284278241"
                if str(value) == "15":
                    v6 = "2667308083579209880"
                url =url+'{"name":"本市居住区","value":"'+v6+'"},'
            if str(key) == 'address':
                url =url+'{"name":"在津居住地","value":"'+str(value)+'"},'
            if str(key) == 'return_time':
                url =url+'{"name":"返岗日期","value":"'+str(value)+'"},'
            if str(key) == 'latest_hs_time':
                url =url+'{"name":"最后一次核酸日期","value":"'+str(value)+'"},'
            if str(key) == 'belong_street':
                 url =url+'{"name":"本市居住地所属街道","value":"'+str(StreetInfo.objects.get(street_name=value).zy_id)+'"},'
            if str(key) == 'health_code':
                v2 = "849868123478574657"
                if str(value) == "1":
                    v2 = "7444163642894667115"
                if str(value) == "2":
                    v2 = "-1280300500985427099"
                url =url+'{"name":"健康码","value":"'+v2+'"},'
            if str(key) == 'lxks':
                url =url+'{"name":"责任部门","value":"'+str(value)+'"},'
            if str(key) == 'wgy_name':
                url =url+'{"name":"网格员","value":"'+str(value)+'"},'
        url =url+'{"name":"报备类型","value": "-8479088515780359521"}'
        #url = url.strip(',')
        url = url+']'
        logger.info("SDK======返岗========"+url)
        print(url)
        res = requests.post(url)
        print(res.json())
    
    def dj_to_zy(ob,fg_type,logger):
        url = 'http://111.30.78.81:8018/third/sysService.jsp?method=bbxxsj&body=['
        params_json = json.loads(json.dumps(ob))
        items = params_json.items()
        logger.info("SDK======抵津=====json=== %s" % (params_json))
        for key, value in items:
            if str(key) == 'user_name':
                url =url+'{"name":"姓名","value":"'+str(value)+'"},'
            if str(key) == 'phone_number':
                url =url+'{"name":"主手机号","value":"'+str(value)+'"},'
            if str(key) == 'user_type':
                v = "-1011829781299903333"
                if str(value) == "1":
                    v = "-2697056394220843866"
                if str(value) == "2":
                    v = "-6628758109765353450"
                if str(value) == "3":
                    v = "-6848205106814367273"
                if str(value) == "4":
                    v = "8589023072944867380"
                url =url+'{"name":"人员类型","value": "'+v+'"},'
            if str(key) == 'credential_type':
                v1 = "-2163949937512004517"
                if str(value) == "1":
                    v1 = "-120587067059975033"
                url =url+'{"name":"证件类型","value": '+v1+' },'
            if str(key) == 'id_card_num':
                url =url+'{"name":"证件号","value":"'+str(value)+'"},'
            if str(key) == 'company_name':
                url =url+'{"name":"单位名称","value":"'+str(value)+'"},'
            if str(key) == 'work_area':
                url =url+'{"name":"工作区域或者岗位","value":"'+str(value)+'"},'
            if str(key) == 'habitation_area':
                v6 = "6249666976084412847"
                if str(value) == "0":
                    v6 = "6249666976084412847"
                if str(value) == "1":
                    v6 = "7577884879151841687"
                if str(value) == "2":
                    v6 = "-1841404495153902540"
                if str(value) == "3":
                    v6 = "-7836971642085881951"
                if str(value) == "4":
                    v6 = "-7022987771455910953"
                if str(value) == "5":
                    v6 = "-7436135588797857361"
                if str(value) == "6":
                    v6 = "3562988799050337284"
                if str(value) == "7":
                    v6 = "-559088388398299686"
                if str(value) == "8":
                    v6 = "6112140215708893861"
                if str(value) == "9":
                    v6 = "-6528412264235514711"
                if str(value) == "10":
                    v6 = "8632096367376154741"
                if str(value) == "11":
                    v6 = "1067848193873626121"
                if str(value) == "12":
                    v6 = "-7403414504862822800"
                if str(value) == "13":
                    v6 = "1353876058778518827"
                if str(value) == "14":
                    v6 = "1601061402284278241"
                if str(value) == "15":
                    v6 = "2667308083579209880"
                url =url+'{"name":"本市居住区","value":"'+v6+'"},'
            if str(key) == 'address':
                url =url+'{"name":"在津居住地","value":"'+str(value)+'"},'
            if str(key) == 'latest_hs_time':
                url =url+'{"name":"最后一次核酸日期","value":"'+str(value)+'"},'
            if str(key) == 'belong_street':
                url =url+'{"name":"本市居住地所属街道","value":"'+str(StreetInfo.objects.get(street_name=value).zy_id)+'"},'
            if str(key) == 'source_address':
                url =url+'{"name":"来源地具体地址","value":"'+str(value)+'"},'
            if str(key) == 'arrrive_time':
                url =url+'{"name":"抵津日期","value":"'+str(value)+'"},'
            if str(key) == 'arrive_type':
                v5 = "6459274140710159158"
                if str(value) == "1":
                    v5 = "-1114039255751833633"
                if str(value) == "2":
                    v5 = "8998532771188722755"
                if str(value) == "3":
                    v5 = "-142436149721281651"
                url =url+'{"name":"抵津方式","value":"'+v5+'"},'
#            if str(key) == 'lxks':
#                url =url+'{"name":"责任部门","value":"'+str(value)+'"},'
            if str(key) == 'cch':
                url =url+'{"name":"车牌号","value":"'+str(value)+'"},'
            if str(key) == 'hwmc':
                url =url+'{"name":"货物名称","value":"'+str(value)+'"},'
            if str(key) == 'source_city':
                url =url+'{"name":"来源地省直辖市","value":"'+str(value)+'"},'
            if str(key) == 'source_x_city':
                url =url+'{"name":"来源地地级市区","value":"'+str(value)+'"},'
#            if str(key) == 'ifjk':
#                url =url+'{"name":"是否包含进口货物","value":"'+str(value)+'"},'
#            if str(key) == 'wgy_name':
#                url =url+'{"name":"网格员","value":"'+str(value)+'"},'
#            if str(key) == 'has_high_risk_traval':
#                url =url+'{"name":"中高风险旅居史","value":"'+str(value)+'"},'
#            if str(key) == 'has_covid_report':
#                url =url+'{"name":"是否有核酸报告","value":"'+str(value)+'"},'
            if str(key) == 'covid_test_report_img':
                url =url+'{"name":"核算报告","value":"https://brilliantlife.com.cn:8020/'+str(value)+'"},'
            if str(key) == 'vaccine_state':
                v3 = "944406740328005722"
                if str(value) == "1":
                    v3 ="-5425206302665126618"
                if str(value) == "2":
                    v3 ="2307695624218757903"
                url =url+'{"name":"疫苗接种情况","value":"'+v3+'"},'
            if str(key) == 'health_code':
                v2 = "849868123478574657"
                if str(value) == "1":
                    v2 = "7444163642894667115"
                if str(value) == "2":
                    v2 = "-1280300500985427099"
                url =url+'{"name":"健康码","value":"'+v2+'"},'
        url =url+'{"name":"报备类型","value": "-1084860361741024638"}'
        #url = url.strip(',')
        url = url+']'
        logger.info("SDK=====抵津========="+url)
        res = requests.post(url)
        print(res.json())

# 从致远获取人员信息
    def zy_get_ui(phone_number,logger):
        logger.info("SDK======更新人员信息=====json===")
        url = 'http://111.30.78.81:8018/third/sysService.jsp?method=queryInfo&phone='+phone_number
        res = requests.get(url)
        logger.info("SDK======更新人员信息=====json=== %s" % (res.json()))
        try:
            if res.json()['item16']:
                eui = EpidemicUserInfo.objects.get(phone_number=phone_number)
                eui.zy_id = res.json()['item16']
                eui.id_card_num  = res.json()['item3']
                eui.save()
                logger.info("底册人员======更新人员信息zk_id=====json=== %s" % (res.json()['item16']))
        except:
            logger.info("SDK ======未查出信息zk_id===== 或底册无该人员信息" )
    

    def zy_update_idcard(phone_number,logger):
        logger.info("SDK======更新人员身份证信息=====json===")
        url = 'http://111.30.78.81:8018/third/sysService.jsp?method=queryInfo&phone='+phone_number
        res = requests.get(url)
        logger.info("SDK======更新人员身份证信息=====json=== %s" % (res.json()))
        try:
            if res.json()['item3']:
                eui = EpidemicUserInfo.objects.get(phone_number=phone_number)
                eui.id_card_num  = res.json()['item3']
                eui.save()
                logger.info("底册人员======更新人员身份证信息=====idcard number=== %s" % (res.json()['item3']))
        except:
            logger.info("SDK ======未查出身份证===== 或底册无该人员信息" )

